package com.rainbowred.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.rainbowred.common.pojo.CommonResult;
import com.rainbowred.system.domain.EdpDeveloper;
import com.rainbowred.system.service.EdpDeveloperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.ui.Model;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Objects;

/**
 * @Desc:
 * @Date: 2023/10/30 16:34
 * @Author: pengweibiao
 **/
@Controller
@RequestMapping("/thy/developer")
public class ThyEdpDeveloperController {

    @Autowired
    private EdpDeveloperService service;

    @RequestMapping("/list")
    public String getList(Model model) {
        QueryWrapper<EdpDeveloper> qw = new QueryWrapper<>();
        qw.eq("del_flag", 0).orderBy(true, false, "create_date");
        List<EdpDeveloper> list = service.list(qw);
        model.addAttribute("developers", list);
        return "view/developer/index";
    }

    @RequestMapping("/update/{field}/{id}")
    public String disablePojo(@PathVariable(value = "field") String field, @PathVariable(value = "id") String id, Model model) {
        EdpDeveloper pojo = service.getById(id);
        if (Objects.nonNull(pojo)) {
            switch (field) {
                case "disable":
                    if (pojo.getDisable().equals(1)) {
                        pojo.setDisable(0);
                    }else {
                        pojo.setDisable(1);
                    }
                    break;
                case "del_flag":
                    pojo.setDelFlag(1);
                    break;
                default:
                    break;
            }
            service.updateById(pojo);
        }
        return "redirect:/thy/developer/list";
    }


}
